<template>
  <span>
    <el-dialog title="管理员权限修改" :visible.sync="dialogFormVisible" @close='handleClose'>
      <!-- 表单 -->
      <el-form :model="form" status-icon :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名：" prop="userName">
          <el-input placeholder="请输入用户名" v-model="form.userName" ></el-input>
        </el-form-item>
        <el-form-item label="手机号：" prop="telphone">
          <el-input placeholder="请输入用户名" type="number" v-model="form.telphone" ></el-input>
        </el-form-item> 
        <el-form-item label="认证状态">
          <el-radio-group v-model="form.authority">
            <el-radio :label="1" >已认证</el-radio>
            <el-radio :label="0">未认证</el-radio>
          </el-radio-group>
        </el-form-item>                       
      </el-form>
      <!-- 确认按钮 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
      </div>
    </el-dialog>
  </span>  
</template>
<script>
export default {
  name:'adminModifyRole',  
  data() {
    return {
      form: {
        userName:'',
        telphone:'',
        authority:'',
        id:''
      },
      dialogFormVisible: true,
      formLabelWidth: '80px',
      rules: {
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
        ],
        telphone: [
          { required: true, message: '请手机号', trigger: 'blur' },
          { min: 11, max: 11, message: '长度为11位数字', trigger: 'blur' }
        ]
      }    
    }
  },
  created(){
    const id=this.$route.query.id
    this.form.userName=id[0].username
    this.form.telphone=id[0].telphone
    this.form.id=id[0].id
    this.form.authority=id[0].authority
  },
  methods:{ 
    postAdimnData(){
      this.axios.post('/api/user/edit',{
        params:{
          id:this.form.id,
          username:this.form.userName,
          telphone:this.form.telphone,
          authority:this.form.authority
        }
      }).then((res)=>{
        // 修改成功
        this.message('修改成功','success')
      }).catch((error)=>{
        this.message('服务器忙，请稍后重试','error')
      })
    },   
    handleClose(){
      this.$router.go(-1)
    },
    handleCancel(){
      this.dialogFormVisible=false
    },
    submitForm(ruleForm){
      this.dialogFormVisible = false
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          // 提交修改
          this.postAdimnData()          
        } else {
          this.message('服务器忙，请稍后重试','error')
          return false;
        }
      });
    },
     // 失败提示
    message(msg,type){
      this.$message({
        message:msg,
        type
      })
    }
  }
}
</script>
<style scoped>

</style>